package com.thankcreate.model;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.Marshaller.Listener;

import org.eclipse.core.runtime.ListenerList;



public class ContactGroup extends Contact {

	private List entries;

	private ListenerList listeners;
	
	public ContactGroup(String name, String sex, int photoIndex, Contact parent, List entries) {
		super(name, sex, photoIndex,parent);
		this.entries = entries;
	}

	public ContactGroup(String name, String sex, int photoIndex,
			ContactGroup parent) {
		super(name, sex, photoIndex, parent);
	}
	
	public ListenerList getListeners() {
		return listeners;
	}

	public void setListeners(ListenerList listeners) {
		this.listeners = listeners;
	}

	public Contact[] getEntries(){
		if (entries != null)
			return (Contact[]) entries.toArray(new Contact[entries.size()]);
		return new Contact[0];
	}
	
	@Override
	public void addEntry(Contact ob) {
		// TODO Auto-generated method stub
		if(entries == null){
			entries = new ArrayList(10);			
		}
		entries.add(ob);
		ob.setParent(this);
		fireContactChanged();
	}

	@Override
	public void removeEntry(Contact ob) {
		// TODO Auto-generated method stub
		if(entries != null){
			if(!entries.isEmpty()){
				entries.remove(ob);
			}
		}
		fireContactChanged();
	}

	@Override
	public boolean isEmpty() {
		// TODO Auto-generated method stub
		if(entries == null){
			return true;
		}
		return entries.isEmpty();
	}
	
	public void addListener(IContactListener contactListener){
		if(getParent() != null){
			getParent().addListener(contactListener);
		}else{
			if (listeners == null)
				listeners = new ListenerList();
			listeners.add(contactListener);
		}
	}	
}
